﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AjaxTest.aspx.cs" Inherits="ZLCMS.Web.Example.AjaxTest" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<style type="text/css">
    body {  font: 11pt Trebuchet MS;
            font-color: #000000;
            padding-top: 72px;
            text-align: center }

    .text { font: 8pt Trebuchet MS }
</style>

<title>AJAX示例，使用ASP.NET AJAX，但不使用控件</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>
    
    <div>
        <asp:ScriptManagerProxy  ID="ScriptManagerProxy1" runat="server">
<%--
            <Scripts>
                <asp:ScriptReference Path="CallWebServiceMethods.js" />
            </Scripts>
--%>
            <Services>
                <asp:ServiceReference Path="~/AJAXServer/Example/AjaxExampleServer.asmx" />
            </Services>
        </asp:ScriptManagerProxy >
        
       <table>
        <tr align="left"><td colspan="2">AJAX示例，使用ASP.NET AJAX，但不使用控件</td></tr>
        <tr align="left">
            <td>Method that does not return a value:</td>
            <td>
                <!-- Getting no retun value from 
                the Web service. --> 
                <button id="Button2"  
                    onclick="GetNoReturn()">No Return</button>
            </td>
        </tr>

        <tr align="left">
            <td>Method that returns a value:</td>
            <td>
                <!-- Getting a retun value from 
                the Web service. --> 
                <button id="Button3" 
                    onclick="GetTime(); return false;">Server Time</button>
            </td>
       </tr>

       <tr align="left">
            <td>Method that takes parameters:</td>
            <td>
                <!-- Passing simple parameter types to 
                the Web service. --> 
                <button id="Button4" 
                    onclick="Add(20, 30); return false;">Add</button>
            </td>

        </tr>

        <tr align="left">
            <td>Method that returns XML data:</td>
            <td>   
                 <!-- Get Xml. --> 
                <button id="Button5" 
                    onclick="GetXmlDocument(); return false;">Get Xml</button>
            </td>
        </tr>
        <tr align="left">
            <td>Method that uses GET:</td>
            <td>   
                 <!-- Making a GET Web request. --> 
                <button id="Button6" 
                    onclick="MakeGetRequest(); return false;">Make GET Request</button>
            </td>
        </tr>
        <tr align="left"><td colspan="2">
            【<span id="ResultId"></span>】
        </td></tr>

    </table>
        
    </div>
    </form>
     


    
<script type="text/javascript">
// This function calls the Web service method without 
// passing the callback function. 
function GetNoReturn()
{
    ZLCMS.Web.AJAXServer.Example.AjaxExampleServer.GetServerTime();
    alert("This method does not return a value.");

}


// This function calls the Web service method and 
// passes the event callback function.  
function GetTime()
{
    ZLCMS.Web.AJAXServer.Example.AjaxExampleServer.GetServerTime(
    SucceededCallback);

}


// This function calls the Web service method 
// passing simple type parameters and the 
// callback function  
function Add(a,  b)
{
    ZLCMS.Web.AJAXServer.Example.AjaxExampleServer.Add(a, b, 
    SucceededCallback);
}

// This function calls the Web service method 
// that returns an XmlDocument type.  
function GetXmlDocument() 
{
    ZLCMS.Web.AJAXServer.Example.AjaxExampleServer.GetXmlDocument(
        SucceededCallbackWithContext, FailedCallback,
        "XmlDocument")
}

// This function calls a Web service method that uses
// GET to make the Web request.
function MakeGetRequest() 
{

    ZLCMS.Web.AJAXServer.Example.AjaxExampleServer.EchoStringAndDate(
        new Date("1/1/2007"), " Happy",
        SucceededCallback, 
        FailedCallback, "HappyNewYear");

}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object, the user context, and the 
// calling method name as parameters.
function SucceededCallbackWithContext(result, userContext, methodName)
{
    var output;

    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");

    var readResult;
    if (userContext == "XmlDocument")
	{
	
	    if (document.all) 
	        readResult = 
		        result.documentElement.firstChild.text;
		else
		    // Firefox
		   readResult =
		        result.documentElement.firstChild.textContent;
		
	     RsltElem.innerHTML = "XmlDocument content: " + readResult;
	}

}

// This is the callback function invoked if the Web service
// succeeded.
// It accepts the result object as a parameter.
function SucceededCallback(result, eventArgs)
{
    // Page element to display feedback.
    var RsltElem = document.getElementById("ResultId");
    RsltElem.innerHTML = result;
}


// This is the callback function invoked if the Web service
// failed.
// It accepts the error object as a parameter.
function FailedCallback(error)
{
    // Display the error.    
    var RsltElem = 
        document.getElementById("ResultId");
    RsltElem.innerHTML = 
    "Service Error: " + error.get_message();
}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

</script>
</body>
</html>
